/*! \file provider.h
 *	\brief <write description for provider.h>
 *
 *	created:	2009/11/20
 *	created:	20:11:2009   18:19
 *	filename: 	o:\main\libs\mem\impl\provider.h
 *	file path:	o:\main\libs\mem\impl
 *	file base:	provider
 *	file ext:	h
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */

#ifndef _MEM_PROVIDER_H_
#define _MEM_PROVIDER_H_

#pragma once

#include "../defs.h"

#if TT_MEM_ENABLED && TT_MEM_PROFILING

#include "block_info.h"

namespace tt{
namespace mem{
namespace impl{

class Provider
{
public:
	Provider();
	~Provider();

	BlockInfo* active_section() const;
	BlockInfo* root_section(const char* section_name);

	void section_start(const char* section_name, BlockInfo*& section, BlockInfo*& previous);
	void section_start_to_root(const char* section_name, BlockInfo*& section, BlockInfo*& previous);
	void section_end(BlockInfo* section, BlockInfo* previous);

	//registering memory events in current section
	BlockInfo* register_new(std::size_t size);
	BlockInfo* register_new_array(std::size_t size);
	void register_new(BlockInfo* section, std::size_t size);
	void register_new_array(BlockInfo* section, std::size_t size);
	void register_delete(BlockInfo* section, std::size_t size);
	void register_delete_array(BlockInfo* section, std::size_t size);

	void serialize(const char* file_name, bool append) const;

private:
	BlockInfo m_root;
	BlockInfo* m_active_section;
};

Provider& g_provider();

} //impl
} //mem
} //namespace tt

#endif //TT_MEM_ENABLED && TT_MEM_PROFILING

#endif //_MEM_PROVIDER_H_
